package com.ikan.positionserver.util;

import com.google.common.collect.Lists;
import com.ikan.positionserver.dto.DeviceUnitDto;
import com.ikan.positionserver.dto.RackColumnDto;
import com.ikan.positionserver.dto.RackDto;
import com.ikan.positionserver.dto.RoomDto;
import com.ikan.positionserver.entity.DeviceUnit;
import com.ikan.positionserver.entity.Rack;
import com.ikan.positionserver.entity.RackColumn;
import com.ikan.positionserver.entity.Room;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

@Slf4j
@UtilityClass
public class DtoConvertor {

    public static final RackDto convert2Dto(Rack rack) {
        if (rack == null) {
            return null;
        }
        RackDto rackDto = new RackDto();
        rackDto.setId(rack.getId());
        rackDto.setName(rack.getName());
        rackDto.setRackType(rack.getRackType());
        rackDto.setHoleId(rack.getHoleId());
        rackDto.setHoleName(rack.getHoleName());
        rackDto.setColumnId(rack.getColumnId());
        rackDto.setColumnName(rack.getColumnName());
        rackDto.setRoomId(rack.getRoomId());
        rackDto.setRoomName(rack.getRoomName());
        rackDto.setCreateTime(rack.getCreateTime());
        rackDto.setCreator(rack.getCreator());
        rackDto.setUpdateTime(rack.getUpdateTime());
        rackDto.setUpdator(rack.getUpdator());
        rackDto.setBizType(rack.getBizType());
        return rackDto;
    }

    public static final List<RackDto> convertRackList2Dto(List<Rack> rackList) {
        if (rackList == null) {
            return null;
        }
        List<RackDto> rackDtoList = Lists.newArrayList();
        for (Rack rack : rackList) {
            RackDto rackDto = convert2Dto(rack);
            rackDtoList.add(rackDto);
        }
        return rackDtoList;
    }

    public static final RackColumnDto convert2Dto(RackColumn rackColumn) {
        if (rackColumn == null) {
            return null;
        }
        RackColumnDto rackColumnDto = new RackColumnDto();
        rackColumnDto.setId(rackColumn.getId());
        rackColumnDto.setName(rackColumn.getName());
        rackColumnDto.setRoomId(rackColumn.getRoomId());
        rackColumnDto.setRoomName(rackColumn.getRoomName());
        rackColumnDto.setCreateTime(rackColumn.getCreateTime());
        rackColumnDto.setCreator(rackColumn.getCreator());
        rackColumnDto.setUpdateTime(rackColumn.getUpdateTime());
        rackColumnDto.setUpdator(rackColumn.getUpdator());
        return rackColumnDto;
    }

    public static final List<RackColumnDto> convertRackColumn2DtoList(List<RackColumn> rackColumnList) {
        if (rackColumnList == null) {
            return null;
        }
        List<RackColumnDto> rackColumnDtoList = Lists.newArrayList();
        for (RackColumn rack : rackColumnList) {
            RackColumnDto rackDto = convert2Dto(rack);
            rackColumnDtoList.add(rackDto);
        }
        return rackColumnDtoList;
    }

    public static final RoomDto convert2Dto(Room room) {
        if (room == null) {
            return null;
        }
        RoomDto roomDto = new RoomDto();
        roomDto.setId(room.getId());
        roomDto.setName(room.getName());
        roomDto.setCreateTime(room.getCreateTime());
        roomDto.setCreator(room.getCreator());
        roomDto.setUpdateTime(room.getUpdateTime());
        roomDto.setUpdator(room.getUpdator());
        return roomDto;
    }

    public static final List<RoomDto> convertRoom2DtoList(List<Room> roomList) {
        if (roomList == null) {
            return null;
        }
        List<RoomDto> roomDtoList = Lists.newArrayList();
        for (Room room : roomList) {
            RoomDto rackDto = convert2Dto(room);
            roomDtoList.add(rackDto);
        }
        return roomDtoList;
    }

    public static final DeviceUnitDto convert2Dto(DeviceUnit deviceUnit) {
        if (deviceUnit == null) {
            return null;
        }
        DeviceUnitDto deviceUnitDto = new DeviceUnitDto();
        deviceUnitDto.setId(deviceUnit.getId());
        deviceUnitDto.setRackId(deviceUnit.getRackId());
        deviceUnitDto.setRackName(deviceUnit.getRackName());
        deviceUnitDto.setSeq(deviceUnit.getSeq());
        deviceUnitDto.setCreateTime(deviceUnit.getCreateTime());
        deviceUnitDto.setCreator(deviceUnit.getCreator());
        deviceUnitDto.setUpdateTime(deviceUnit.getUpdateTime());
        deviceUnitDto.setUpdator(deviceUnit.getUpdator());
        return deviceUnitDto;
    }

    public static final List<DeviceUnitDto> convertServerUnitList2Dto(List<DeviceUnit> serverUnitList) {
        if (serverUnitList == null) {
            return null;
        }
        List<DeviceUnitDto> deviceUnitDtoList = Lists.newArrayList();
        for (DeviceUnit rack : serverUnitList) {
            DeviceUnitDto rackDto = convert2Dto(rack);
            deviceUnitDtoList.add(rackDto);
        }
        return deviceUnitDtoList;
    }


}
